﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Menus;
using Menus.Model;

namespace Menus
{
    // Declaration
    public delegate void LoadGridViewDelegate();

    public partial class fmPlatsList : Form
    {
        #region -------------------------------------------------------------public
        
        public int xPosForm
        {
            get { return _xPosForm; }
            set { _xPosForm = value; }
        }

        public int yPosForm
        {
            get { return yPosForm; }
            set { _yPosForm = value; }
        }

        public int widthForm
        {
            get { return _widthForm; }
            set { _widthForm = value; }
        }

        public fmPlatsList()
        {
            InitializeComponent();
        }

        #endregion


        #region ---------------------------------------------------------------private

        private int _xPosForm;
        private int _yPosForm;
        private int _widthForm;

        AutoCompleteStringCollection colValues = new AutoCompleteStringCollection();

        /// <summary>fmPlats_Load(object sender, EventArgs e)
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void fmPlats_Load(object sender, EventArgs e)
        {
            Left = _xPosForm;
            Top = _yPosForm;
            Width = _widthForm;

            LoadGridView();
        }

        /// <summary>LoadGridView()
        /// chargement du GridView
        /// </summary>
        private void LoadGridView()
        {
            PlatManager platManager = new PlatManager();
            dataGridView1.DataSource = platManager.GetListPlat();
            dataGridView1.Columns["ID"].Visible = false;
            dataGridView1.Columns["Ingredient"].Visible = false;
            dataGridView1.Columns["Libelle"].Width = dataGridView1.Width;

            dataGridView1.AllowDrop = false;
            dataGridView1.AllowUserToAddRows = false;
            dataGridView1.AllowUserToDeleteRows = false;
            dataGridView1.AllowUserToResizeColumns = false;
            dataGridView1.AllowUserToResizeRows = false;        
        }

        /// <summary> btnAddPlat_Click
        /// Ajout d'un plat
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnAddPlat_Click(object sender, EventArgs e)
        {
            LoadGridViewDelegate myDelegate = new LoadGridViewDelegate(LoadGridView); 
            
            fmPlatDetail form = new fmPlatDetail(myDelegate);
            form.ShowDialog();
        }

        /// <summary>dataGridView1_CellDoubleClick
        /// dataGridView1_CellDoubleClick
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            LoadGridViewDelegate myDelegate = new LoadGridViewDelegate(LoadGridView);
            var idPlat = Int32.Parse(dataGridView1[0, e.RowIndex].Value.ToString());
            fmPlatDetail form = new fmPlatDetail(myDelegate, idPlat);
            form.ShowDialog();
        }

        #endregion


    }
}
